| Conditions | 4 |
| Paths | 6 |
| Total Lines | 76 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | /* |
||
| 37 | async.eachSeries(this.files, function(f, next) { |
||
| 38 | |||
| 39 | /** |
||
| 40 | * Create folder for the dest file |
||
| 41 | */ |
||
| 42 | grunt.file.mkdir(path.dirname(f.dest)); |
||
| 43 | var args = []; |
||
| 44 | |||
| 45 | /** |
||
| 46 | * Quality scale: Minimum allowed is 84. |
||
| 47 | */ |
||
| 48 | if (options.quality) { |
||
| 49 | if (options.quality < 84) { |
||
| 50 | grunt.fail.warn('Guetzli: Quality must be >= 84 to avoid noticeable artifacts.'); |
||
| 51 | } |
||
| 52 | args.push('--quality'); |
||
| 53 | args.push(options.quality); |
||
| 54 | } |
||
| 55 | |||
| 56 | /** |
||
| 57 | * Outputs the rules that have been matched. |
||
| 58 | */ |
||
| 59 | if (options.verbose) { |
||
| 60 | args.push('--verbose'); |
||
| 61 | } |
||
| 62 | |||
| 63 | args.push(f.src); |
||
| 64 | args.push(f.dest); |
||
| 65 | |||
| 66 | /** |
||
| 67 | * Outputs the file that is being analysed. |
||
| 68 | */ |
||
| 69 | grunt.log.subhead('Compressing: ' + f.dest); |
||
| 70 | var child = grunt.util.spawn({ |
||
| 71 | cmd: guetzli_bin, |
||
| 72 | args: args |
||
| 73 | }, function(error, result, code) { |
||
| 74 | //grunt.log.writeln(code+''+result); |
||
| 75 | if (code !== 0) { |
||
| 76 | return grunt.warn(String(code)); |
||
| 77 | } |
||
| 78 | else{ |
||
| 79 | var source = fs.statSync(f.src[0])['size']; |
||
| 80 | var dest = fs.statSync(f.dest)['size']; |
||
| 81 | var diff = ((source - dest) / source) * 100; |
||
| 82 | diff = Number((diff).toFixed(2)); |
||
| 83 | source_total += source; |
||
| 84 | if (diff < 0) { |
||
| 85 | oversize_total++; |
||
| 86 | source_total += source; |
||
| 87 | diff = diff * -1; |
||
| 88 | if (options.deleteLarger) { |
||
| 89 | grunt.file.delete(f.dest); |
||
| 90 | grunt.log.writeln('Deleted: '['yellow'] + diff + '% larger than its source.'); |
||
| 91 | } |
||
| 92 | else { |
||
| 93 | dest_total += dest; |
||
| 94 | grunt.log.writeln('Warning: '['yellow'] + diff + '% larger than its source. Left undeleted.'); |
||
| 95 | } |
||
| 96 | } |
||
| 97 | else { |
||
| 98 | dest_total += dest; |
||
| 99 | grunt.log.oklns('Done: '['green'] + diff + '% smaller | ' + diff + '%: ' + source + ' -> ' + dest); |
||
| 100 | } |
||
| 101 | } |
||
| 102 | |||
| 103 | next(error); |
||
|
|
|||
| 104 | }); |
||
| 105 | |||
| 106 | /** |
||
| 107 | * displays the output and error streams via the parent process. |
||
| 108 | */ |
||
| 109 | child.stdout.pipe(process.stdout); |
||
| 110 | child.stderr.pipe(process.stderr); |
||
| 111 | |||
| 112 | }.bind(this), function() { |
||
| 113 | var total_diff = (source_total - dest_total) / source_total; |
||
| 131 |